package com.etc.register.controller;

import com.etc.register.entity.Contact;
import com.etc.register.service.ContactService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName ContactController
 * @Description 紧急联系人表
 * @Author   聪
 * @Date 2019/8/10 15:41
 * @Version 1.0
 */
@RestController
@RequestMapping("contact")
public class ContactController {
    @Autowired
    private ContactService contactService;

    //查询
    @GetMapping("findAll")
    public List<Contact> findAll() {
        return contactService.findByAll();
    }

    //   添加
    @GetMapping("save")
    public Contact save(String person, String relation, String contacts, String unit) {
        Contact save = contactService.save(new Contact(person, relation, contacts, unit));
        return save;
    }

    //   删除
    @GetMapping("deleteById")
    public Integer deleteById(Integer tid) {
        Integer integer = contactService.deleteById(tid);
        if (integer == 1) {
            return 1;
        } else {
            return 0;
        }
    }
}